document.getElementById("begin_time") && bmCommonFun.initDateTimePicker("begin_time");
document.getElementById("end_time") && bmCommonFun.initDateTimePicker("end_time");

search_data && bmCommonFun.searchList({
    url: search_data.url,
    data: search_data.data,
    callbackFun: function(){
        avalon.scan(document.getElementById("users"));
    }
});


var vm_main = avalon.define({
    $id: "vm-users",
    htmlEdit: `<div style="padding:15px 20px;" ms-important="vm-edit_id" id="edit_id" class="ms-controller">
                                <form class="form-horizontal">
                                    <div class="form-group">
                                        <label for="name" class="col-sm-4 control-label">所属业务员ID:</label>
                                        <div class="col-sm-7">
                                            <input type="text" class="form-control" id="name" ms-duplex="@form_data.bm_qrcode_id">
                                        </div>
                                    </div>
                                </form>
                                <a class="btn btn-primary mt-20" ms-click="@submit" style="margin-left:164px;">确认修改</a>
                            </div>`,
    edit(id, bm_qrcode_id){
        let self = this;
        vm_edit.form_data = {
            bm_qrcode_id: bm_qrcode_id,
            id: id
        };
        setTimeout(() => {
            layer.open({
                type: 1,
                title: '编辑',
                skin: 'layui-layer-rim',
                area: ['500px', '200px'],
                content: self.htmlEdit,
                success: function(layero, index){
                    avalon.scan(document.getElementById('edit_id'));
                },
                cancel: function(index, layero){ 
                    vm_edit.form_data = {
                        bm_qrcode_id: '',
                        id: ''
                    }
                }
            });
        },500);
    }
});

var vm_edit = avalon.define({
    $id: "vm-edit_id",
    form_data: {
        bm_qrcode_id: '',
        id: ''
    },
    check(){
    	let self = this;
	 	if ($checkAction.checkEmpty(self.form_data.bm_qrcode_id)) {
            layer.msg('请输入所属业务员ID');
            return false;
        }
        else{
        	return true;
        }
    },
    submit() {
        // 提交创建
        if(this.check()){
            layer.load();
            $handleAjax.handle({
                url: APP_ROOT + "/mapi/index.php?ctl=user_two&act=edit_qrcode_id",
                isTip: false,
                data: this.form_data
            }).done(function(result){
                layer.closeAll();
                if(result.status == 1){
                    layer.msg(result.error || '操作成功',{
                        time: 1000
                    });
                    setTimeout(function(){
                        location.href = TMPL_REAL + "/index.php?ctl=user_two&act=users";
                    }, 1000);
                }
                else{
                    layer.msg(result.error || '操作失败');
                }

            }).fail(function(err){
                console.log(err);
            });
        }
    }
});